#include <stdio.h>
int main()
{
    int m = 0, n = 0, i = 0, j = 0, k = 0;
    int a[10][10] = { 0 };
    scanf_s("%d %d", &m, &n);
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            scanf_s("%d", &a[i][j]);
        }
    }
    for (i = 0; i < n; i++)
    {
        for (k = n - 1; k >= 0; k--)
        {
            a[i][k + 1] = a[i][k];
            if (k == 0)
            {
                a[i][0] = a[i][k + 1];
            }
        }
    }
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            printf("%d ", a[i][j]);
        }
        printf("\n");
    }
    return 0;
}